package com.shun.servlet;

import com.shun.service.UserService;
import com.shun.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/registerServlet")
public class registerServlet extends HttpServlet {
    private UserService userService=new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Type","text/html;character=utf-8");
        //获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String cPassword = request.getParameter("cPassword");
        String msg1= userService.register(username, password, cPassword);
        if(msg1.equals("注册成功")){
            request.getSession().setAttribute("msg1",msg1);
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }
        else {
            request.getSession().setAttribute("msg1",msg1);
            request.getRequestDispatcher("register.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
